package com.sangcomz.fishbun.util;

import com.sangcomz.fishbun.ResourceTable;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.*;
import ohos.agp.components.element.Element;
import ohos.agp.components.element.PixelMapElement;
import ohos.agp.components.element.ShapeElement;
import ohos.agp.utils.Color;
import ohos.app.Context;

public class CommonToolbar extends StackLayout {

    public DirectionalLayout toolbarLayout;
    public StackLayout btnBack;
    public Image imgBack;
    public Text tvTitle;
    public StackLayout btnSelect;
    public Image imgSelect;
    public StackLayout btnSelectAll;
    public Image imgSelectAll;
    public Button btnSelectTitle;
    public Button btnSelectAllTitle;

    public CommonToolbar(Context context) {
        super(context);
    }

    public CommonToolbar(Context context, AttrSet attrSet) {
        super(context, attrSet);
        initView(context);
    }

    public CommonToolbar(Context context, AttrSet attrSet, String styleName) {
        super(context, attrSet, styleName);
    }

    private void initView(Context context) {
        Component component = LayoutScatter.getInstance(context).parse(ResourceTable.Layout_common_toolbar, this, true);

        toolbarLayout = (DirectionalLayout) component.findComponentById(ResourceTable.Id_toolbar_layout);

        btnBack = (StackLayout) component.findComponentById(ResourceTable.Id_btn_back);
        imgBack = (Image) component.findComponentById(ResourceTable.Id_btn_back_img);
        tvTitle = (Text) component.findComponentById(ResourceTable.Id_tv_title);
        btnSelect = (StackLayout) component.findComponentById(ResourceTable.Id_btn_select);
        imgSelect = (Image) component.findComponentById(ResourceTable.Id_btn_select_img);
        btnSelectAll = (StackLayout) component.findComponentById(ResourceTable.Id_btn_select_all);
        imgSelectAll = (Image) component.findComponentById(ResourceTable.Id_btn_select_all_img);

        btnSelectTitle = (Button) component.findComponentById(ResourceTable.Id_btn_select_title);
        btnSelectAllTitle = (Button) component.findComponentById(ResourceTable.Id_btn_select_all_title);
    }

    public void hideAllSelectBtn() {
        btnSelect.setVisibility(HIDE);
        btnSelectAll.setVisibility(HIDE);
        btnSelectTitle.setVisibility(HIDE);
        btnSelectAllTitle.setVisibility(HIDE);
    }

    public void setBackgroundColor(int color) {
        ShapeElement background = new ShapeElement();
        background.setRgbColor(new RgbColor(color));
        toolbarLayout.setBackground(background);
    }

    public void setBackgroundColor(RgbColor color) {
        ShapeElement background = new ShapeElement();
        background.setRgbColor(color);
        toolbarLayout.setBackground(background);
    }

    public void setTitle(String title,int color) {
        tvTitle.setVisibility(VISIBLE);
        tvTitle.setText(title);
        tvTitle.setTextColor(new Color(color));
    }

    public void setBtnSelectTitle(String title, int color) {
        btnSelectTitle.setVisibility(VISIBLE);
        btnSelectTitle.setText(title);
        btnSelectTitle.setTextColor(new Color(color));
    }

    public void setImgBack(Element element) {
        imgBack.setImageElement(element);
    }

    public void setImgSelect(Element element) {
        imgSelect.setImageElement(element);
    }

    public void setImgSelectAll(Element element) {
        imgSelectAll.setImageElement(element);
    }
}
